a = int(input())
mp = 0
if a < 1000 or a > 9999:
    print ("O")
else:
    a1 = a//1000
    a2 = a//100%10
    a3 = a//10%10
    a4 = a%10
    cd = 0 
    for i in range(1, a1+1):
        if a1%i == 0:
            cd += 1
    if cd == 2 and a1 > mp:
        mp = a1
    cd = 0 
    for i in range(1, a2+1):
        if a2%i == 0:
            cd += 1
    if cd == 2 and a2 > mp:
        mp = a2
    cd = 0
    for i in range(1, a3+1):
        if a3%i == 0:
            cd += 1
    if cd == 2 and a3 >= mp:
        mp = a3
    cd = 0
    for i in range(1, a4+1):
        if a4%i == 0:
            cd += 1
    if cd == 2 and a4 >= mp:
        mp = a4
    cd = 0
    d = a1*10 + a2
    for i in range(1, d+1):
        if d%i == 0:
            cd += 1
    if cd == 2 and d >= mp:
        mp = d
    cd = 0
    d = a1*100 + a2*10 + a3
    for i in range(1, d+1):
        if d%i == 0:
            cd += 1
    if cd == 2 and d >= mp: 
        mp = d
    cd = 0
    d = a1*1000 + a2*100 + a3*10 + a4
    for i in range(1, d+1):
        if d%i == 0:
            cd += 1
    if cd == 2 and a1 >= mp:
        mp = d
    cd = 0
    d = a3*10+a4
    for i in range(1, d+1):
        if d%i == 0:
            cd += 1
    if cd == 2 and d >= mp:
        mp = d
    print(mp)

